package cn.wolfcode.plus.controller;

import cn.wolfcode.plus.domain.Employee;
import cn.wolfcode.plus.service.IEmployeeService;
import cn.wolfcode.plus.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/employees")
public class EmployeeController {

    @Autowired
    private IEmployeeService employeeService;

    @GetMapping()
    public Object list(Employee employee) {
        return employeeService.getListContainDept(employee);
    }

    @PostMapping()
    public JsonResult saveOrUpdate(Employee employee) {

        employeeService.saveOrUpdate(employee);
        return JsonResult.success("操作成功");
    }

    @GetMapping("{id}")
    public Employee detail(@PathVariable("id") Long id) {

        return employeeService.getById(id);
    }

    @DeleteMapping("{id}")
    public JsonResult delete(@PathVariable("id") String id) {

        employeeService.removeById(id);
        return JsonResult.success("删除成功");
    }
}
